package com.ruoyi.analysis.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.analysis.domain.FoodConsume;
import com.ruoyi.analysis.service.IFoodConsumeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 伙食汇总列表Controller
 * 
 * @author ruoyi
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/food")
public class FoodConsumeController extends BaseController
{
    @Autowired
    private IFoodConsumeService foodConsumeService;

//    test
    /**
     * 查询伙食汇总列表列表
     */
    @RequiresPermissions("analysis:food:list")
    @GetMapping("/list")
    public TableDataInfo list(FoodConsume foodConsume)
    {
        startPage();
        List<FoodConsume> list = foodConsumeService.selectFoodConsumeList(foodConsume);
        return getDataTable(list);
    }

    /**
     * 导出伙食汇总列表列表
     */
    @RequiresPermissions("analysis:food:export")
    @Log(title = "伙食汇总列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodConsume foodConsume)
    {
        List<FoodConsume> list = foodConsumeService.selectFoodConsumeList(foodConsume);
        ExcelUtil<FoodConsume> util = new ExcelUtil<FoodConsume>(FoodConsume.class);
        util.exportExcel(response, list, "伙食汇总列表数据");
    }

    /**
     * 获取伙食汇总列表详细信息
     */
    @RequiresPermissions("analysis:food:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(foodConsumeService.selectFoodConsumeById(id));
    }

    /**
     * 新增伙食汇总列表
     */
    @RequiresPermissions("analysis:food:add")
    @Log(title = "伙食汇总列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodConsume foodConsume)
    {
        return toAjax(foodConsumeService.insertFoodConsume(foodConsume));
    }

    /**
     * 修改伙食汇总列表
     */
    @RequiresPermissions("analysis:food:edit")
    @Log(title = "伙食汇总列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodConsume foodConsume)
    {
        return toAjax(foodConsumeService.updateFoodConsume(foodConsume));
    }

    /**
     * 删除伙食汇总列表
     */
    @RequiresPermissions("analysis:food:remove")
    @Log(title = "伙食汇总列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodConsumeService.deleteFoodConsumeByIds(ids));
    }
}
